<?php
class Answer_Component_Controller_Admincp_Level_Edit extends Phpfox_Component {
    public function process() {
        $sLink = "admincp.answer.level";
        if ($aVal = $this->request()->getArray('val')) {
            Phpfox::getService('answer.level')->saveDatabase($aVal);
            $this->url()->send($sLink, array(), Phpfox::getPhrase('answer.level_updated_successfully'));
        }
        if ($iEditId = $this->request()->getInt('id'))
        {
            $aConditions=array('id = '. $iEditId);
            if ($aLevel = Phpfox::getService('answer.level')->getForEdit($aConditions))
            {
                $this->template()->assign('aForms', $aLevel['data']);
            }
        }

        $aGroups = Phpfox::getService('answer.group')->getAllGroup();
        foreach ($aGroups as $iKey => $aVal) {
            if ($aLevel['data']['group_id'] == $aVal['user_group_id']) {
                $aGroups[$iKey]['select'] = "selected=\"selected\"";
            }
            else {
                $aGroups[$iKey]['select'] = "";
            }
            if ($aLevel['data']['previous_group'] == $aVal['user_group_id']) {
                $aGroups[$iKey]['selectPreviousGroup'] = "selected=\"selected\"";
            }
            else {
                $aGroups[$iKey]['selectPreviousGroup'] = "";
            }
        }

        $this->template()
            ->setTitle(Phpfox::getPhrase('answer.edit_level'))
            ->setBreadcrumb(Phpfox::getPhrase('answer.edit_level'))
            ->assign('aGroups', $aGroups);
    }
}